//
//  LJTabbar.m
//  百思不得姐
//
//  Created by 刘鹿杰 on 16/7/3.
//  Copyright © 2016年 刘鹿杰. All rights reserved.
//

#import "LJTabbar.h"

@interface LJTabbar ()

//  加号按钮button
@property (nonatomic, weak) UIButton *addBtn;

@end


@implementation LJTabbar

-(instancetype)initWithFrame:(CGRect)frame{
    
    if (self = [super initWithFrame:frame]) {
        
        [self setBackgroundImage:[UIImage imageNamed:@"tabbar-light"]];

        // 添加一个按钮
        UIButton *addBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        
        [addBtn setBackgroundImage:[UIImage imageNamed:@"tabBar_publish_icon"] forState:UIControlStateNormal];
        
        [addBtn setBackgroundImage:[UIImage imageNamed:@"tabBar_publish_click_icon"] forState:UIControlStateSelected];
        [addBtn sizeToFit];
        
        self.addBtn = addBtn;
    
        [self addSubview:addBtn];
        
    }
    return self;
}

-(void)layoutSubviews{
    
    [super layoutSubviews];

    self.addBtn.center = CGPointMake(self.bounds.size.width * 0.5 , self.bounds.size.height * 0.5);
    
    CGFloat btnX = 0;
    CGFloat btnY = 0;
    CGFloat btnW = KScreenW / 5;
    CGFloat btnH = self.bounds.size.height;
    NSInteger  index = 0;

    for (UIView *btn  in self.subviews) {
        
        if (![btn isKindOfClass:[UIControl class]] || btn == self.addBtn) continue;
        
         btnX = btnW * ((index > 1)?(index + 1):index);
        
        btn.frame = CGRectMake(btnX, btnY, btnW, btnH);
        
        index ++ ;
    }
}

@end
